home *** CD-ROM | disk | FTP | other *** search
- // Copyright 2001 Macromedia, Inc. All rights reserved.
-
- var liveDebugTranslator = false;
- var liveMacBeforeFileName = "Desktop:LiveBeforeTranslation.txt";
- var liveMacAfterFileName = "Desktop:LiveAfterTranslation.txt";
- var liveWinBeforeFileName = "C:\\LiveBeforeTranslation.txt";
- var liveWinAfterFileName = "C:\\LiveAfterTranslation.txt";
-
- var beginLock = "<mm:beginlock translatorClass=\"MM_LIVE_DATA\" type=\"MM_CFML\" orig=\"%s\">";
- var endLock = "<mm:endlock>";
- var translatedAttr = "mmvisible=false";
-
- var serverGeneratedInclude = "\n<SCRIPT LANGUAGE=\"JavaScript\" TYPE=\"text/javascript\" SRC=\"/CFIDE/scripts/cfform.js\"></SCR"+"IPT>\n";
- var serverGeneratedScript = "function _CF_";
- var serverGeneratedObject = "CLASSID=\"clsid:D702FBF4-EE60-11d0-BD5B-00A0C91F4635\"";
- var serverGeneratedMetaTag = "<META content=\"MSHTML 6.00.2600.0\" name=GENERATOR>"
-
-
- function removeHeadOpenTagBegin(name, offset)
- {
- if (name.toUpperCase() == "HEAD")
- headStart = offset;
- }
-
-
-
- function removeHeadCloseTagBegin(name, offset)
- {
- closeTagIsHead = (name.toUpperCase() == "HEAD") ? true : false;
-
- if (closeTagIsHead)
- numHeadsFound++;
- }
-
-
-
- function removeHeadCloseTagEnd(offset)
- {
- if (closeTagIsHead)
- headEnd = offset;
- }
-
-
-
- function removeSecondHead(inStr)
- {
- // Create an object to hold pointers to the callback funcs
- var callbackObj = new Object();
- callbackObj.openTagBegin = removeHeadOpenTagBegin;
- callbackObj.closeTagBegin = removeHeadCloseTagBegin;
- callbackObj.closeTagEnd = removeHeadCloseTagEnd;
-
- // Scan the inStr looking for a second head tag
- numHeadsFound = 0;
- headStart = -1;
- headEnd = -1;
- dreamweaver.scanSourceString(inStr, callbackObj);
-
- // If second head found, return string without it
- if (numHeadsFound > 1)
- return inStr.substring(0, headStart) +
- inStr.substring(headEnd, inStr.length);
-
- // No second head found, so just return inStr
- return inStr;
- }
-
-
-
- function reportError(docNameStr, inStr)
- {
- var translated, errorStr, extraHead, index;
-
- // We're going to abort, so first clean up
- LiveDataTranslator.cleanup();
-
- // The error message will have the wrong column numbers because we've
- // inserted our proprietary labels. Send file to server again without
- // the labels.
- translated = dreamweaver.liveDataTranslate(docNameStr, inStr);
- errorStr = translated.data;
-
- // Our parser gets confused if it finds a second head in the
- // HTML string. Remove the head that's added by ColdFusion.
- errorStr = removeSecondHead(errorStr);
-
- // Tell Dreamweaver to display the error message
- dreamweaver.setLiveDataError(errorStr);
- }
-
-
-
- // If a tag of the specified type surrounds the character at str[index],
- // then remove the entire contents of the tag.
- function removeTag(tagOpen, tagClose, str, index)
- {
- var startIndex = str.lastIndexOf(tagOpen, index);
- var endIndex = str.indexOf(tagClose, index);
- var length = str.length;
- var outStr;
-
- // If opening or closing tag not found, then bail
- if (startIndex == -1 || endIndex == -1)
- return str;
-
- // Add text before tag's opening to outStr
- if (startIndex > 0)
- outStr = str.substring(0, startIndex);
- else
- outStr = "";
-
- // Add text after tag's closing to outStr
- endIndex = endIndex + tagClose.length;
- if (endIndex < length - 1)
- outStr = outStr + str.substring(endIndex, length);
-
- return outStr;
- }
-
-
-
- function liveDataTranslateMarkup(docNameStr, siteRootStr, inStr)
- {
- var labels, translated, outStr, initTags, labelsAndMarker;
-
- if (liveDebugTranslator)
- {
- if ( "macos" == DWfile.getPlatform() )
- DWfile.write( liveMacBeforeFileName, inStr );
- else
- DWfile.write( liveWinBeforeFileName, inStr );
- }
-
- // Refuse to translate if the document's server model is not Cold Fusion
- if (dw.getDocumentDOM().serverModel.getFolderName() != "UD4-ColdFusion")
- return "";
-
- // Refuse to translate if we're not inside a site
- if (siteRootStr.length == 0)
- return "";
-
- // Don't try to translate an empty document
- if (inStr.length == 0)
- return "";
-
- // Send init tags to the server and request requst them
- initTags = dreamweaver.getLiveDataInitTags();
- if (initTags.length > 0)
- {
- // Add a marker at the end so we can check for successful completion
- initTags = initTags + "<!-- MMDW:success -->";
-
- // Send file to server and get the response
- translated = dreamweaver.liveDataTranslate(docNameStr, initTags);
-
- // If we can't find our marker, report that an error occurred
- if (translated.data.lastIndexOf("<!-- MMDW:success -->") == -1)
- {
- if (translated.data.length > 0)
- reportError(docNameStr, initTags);
- return "";
- }
- }
-
- // Specify which tags are cfml: everything with a "cf" prefix
- prefixArray = new Array(1);
- prefixArray[0] = "cf";
-
- // Specify which tags will NOT contain editable HTML in the returned doc
- nonHtmlArray = new Array(10);
- nonHtmlArray[0] = "cfgrid";
- nonHtmlArray[1] = "cfhttp";
- nonHtmlArray[2] = "cfmail";
- nonHtmlArray[3] = "cfquery";
- nonHtmlArray[4] = "cfreport";
- nonHtmlArray[5] = "cfscript";
- nonHtmlArray[6] = "cftree";
- nonHtmlArray[7] = "cfrow";
- nonHtmlArray[8] = "cftable";
- nonHtmlArray[9] = "cfstoredproc";
-
- // Wrap labels around the cfml tags
- LiveDataTranslator.initialize();
- LiveDataTranslator.beginPreTranslate("<!---", "--->", prefixArray, nonHtmlArray);
- dreamweaver.scanSourceString(inStr, LiveDataTranslator);
- labels = LiveDataTranslator.endPreTranslate(inStr);
-
- // The ColdFusion server will replace all the escaped "##" characters that
- // are inside cfoutput tags with an unescaped "#". When we do the "diff"
- // below, we want hashes inside cfoutput tags to be escaped again. The
- // solution is to make every "##" be a "####" right now, so that those
- // previously-escaped "##" characters come back from the server as "##".
- labels = LiveDataTranslator.replaceTextInsideTag(labels,
- "cfoutput", "##", "####");
-
- // Add a marker at the end so we can check for successful completion
- labelsAndMarker = labels + "<!-- MMDW:success -->";
-
- // If we send a file with Mac-style "\r" line endings to a Unix server,
- // the server will ignore the "\r" characters (line ending is "\n" on
- // Unix) and send back a file with no line endings. Instead, we'll
- // convert line endings to "\r\n" before sending to the server.
- labelsAndMarker = LiveDataTranslator.setLineEndingsToMatch("\r\n",
- labelsAndMarker);
-
- // Send file to server and get the response
- translated = dreamweaver.liveDataTranslate(docNameStr, labelsAndMarker);
-
- // If we can't find our marker, report that an error occurred
- index = translated.data.lastIndexOf("<!-- MMDW:success -->");
- if (index == -1)
- {
- if (translated.data.length > 0)
- reportError(docNameStr, inStr);
- LiveDataTranslator.cleanup();
- return "";
- }
- translated.data = translated.data.substr(0, index);
-
- // If the server added script or object tags at the top of the document,
- // then remove them. Otherwise, they may be added to the document without
- // being inside a locked region.
- var bSomethingFound = false;
- var beforeRemoveTag;
- do
- {
- bSomethingFound = false;
- if (index != -1 && inStr.indexOf(serverGeneratedInclude) == -1)
- {
- beforeRemoveTag = translated.data;
- translated.data = translated.data.substring(0, index) + translated.data.substring(index + serverGeneratedInclude.length);
- if (beforeRemoveTag != translated.data)
- bSomethingFound = true;
- }
- index = translated.data.indexOf(serverGeneratedScript);
- if (index != -1 && inStr.indexOf(serverGeneratedScript) == -1)
- {
- beforeRemoveTag = translated.data;
- translated.data = removeTag("\n\r<script", "</scr" + "ipt>\n\r", translated.data, index);
- if (beforeRemoveTag == translated.data)
- translated.data = removeTag("\r\n<script", "</scr" + "ipt>\r\n", translated.data, index);
- if (beforeRemoveTag == translated.data)
- translated.data = removeTag("\n\n<SCRIPT", "</SCR" + "IPT>\n", translated.data, index);
- if (beforeRemoveTag != translated.data)
- bSomethingFound = true;
- }
- index = translated.data.indexOf(serverGeneratedObject);
- if (index != -1 && inStr.indexOf(serverGeneratedObject) == -1)
- {
- beforeRemoveTag = translated.data;
- translated.data = removeTag("\r\n\r\n<OBJECT", "</OBJECT>\r\n\r\n\n\r", translated.data, index);
- if (beforeRemoveTag != translated.data)
- bSomethingFound = true;
- }
- index = translated.data.indexOf(serverGeneratedMetaTag);
- if (index != -1 && inStr.indexOf(serverGeneratedMetaTag) == -1)
- {
- beforeRemoveTag = translated.data;
- translated.data = translated.data.substring(0, index) + translated.data.substring(index + serverGeneratedMetaTag.length);
- if (beforeRemoveTag != translated.data)
- bSomethingFound = true;
- }
- } while (bSomethingFound);
-
- // Some HTTP servers change the line endings in the file
- translated.data = LiveDataTranslator.setLineEndingsToMatch(inStr,
- translated.data);
-
- // If the scripts on the page were not executed or there are no scripts
- // on the page, then just abort
- if (translated.data == labels)
- return "";
-
- // Remove the labels and add lock tags
- LiveDataTranslator.beginPostTranslate();
- dreamweaver.scanSourceString(translated.data, LiveDataTranslator);
- outStr = LiveDataTranslator.endPostTranslate(inStr, translated.data,
- beginLock, endLock, translatedAttr);
- LiveDataTranslator.cleanup();
-
- if (liveDebugTranslator)
- {
- if ( "macos" == DWfile.getPlatform() )
- DWfile.write( liveMacAfterFileName, outStr );
- else
- DWfile.write( liveWinAfterFileName, outStr );
- }
-
- return outStr;
- }
-